package Sort;

import java.util.Arrays;

/**
 * @author zhangmin
 * @create 2022-04-18 10:00
 * 选择排序
 */
public class SelectionSort<T extends Comparable<T>> extends Sort<T>{
    @Override
    public void sort(T[] nums) {
        int n=nums.length;
        for (int i = 0; i < n-1; i++) {
            int min=i;
            for (int j = i+1; j < n; j++) {
                if (less(nums[j],nums[min])){
                    min=j;
                }
            }
            swap(nums,i,min);
        }
    }

    public static void main(String[] args) {
        Integer[] nums={3,5,6,4,1,2};
        SelectionSort<Integer> selectionSort=new SelectionSort<Integer>();
        selectionSort.sort(nums);
        System.out.println(Arrays.toString(nums));
    }
}
